<template>
  <el-container>
    <el-header height="68px" style="line-height: 68px">
      <div style="float:left;">
        <el-radio-group v-model="isCollapse" style="margin-bottom: 2px;">
          <button @click="changeIsCollapse" style="margin-right:12px">
            <i v-if="!isCollapse" class="el-icon-s-fold"></i>
            <i v-else class="el-icon-s-unfold"></i>
          </button>
        </el-radio-group>
      </div>
      <div class="header-title">医院后台管理员系统</div>
      <div class="header-user">
        <div v-if="username">
          欢迎管理员
          <span class="header-username">{{username}}</span>
          退出登录
        </div>
        <div v-if="!username">
          登录
        </div>
      </div>
    </el-header>
    <el-container>
      <el-aside width="auto">
        <el-menu
          default-active="1-4-1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-home"></i>
              <span slot="title">个人中心</span>
            </template>
              <el-menu-item-group>
                <router-link to="/admin/home" tag="span">
                  <el-menu-item index="1-1">个人信息</el-menu-item>
                </router-link>
              </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-office-building"></i>
              <span slot="title">科室管理</span>
            </template>
            <el-menu-item-group>
              <router-link to="/admin/deptInfo" tag="span">
                <el-menu-item index="2-1">查询科室信息</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-user-solid"></i>
              <span slot="title">人员管理</span>
            </template>
            <el-menu-item-group>
              <router-link to="/admin/doctorInfo" tag="span">
                <el-menu-item index="3-1">医护人员信息</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-key"></i>
              <span slot="title">权限管理</span>
            </template>
            <el-menu-item-group>
              <router-link to="/admin/authority" tag="span">
                <el-menu-item index="4-1">角色权限分配</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <div>标签页预留区</div>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    data() {
      return {
        isCollapse: true,
        username: "",
      };
    },
    methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
      changeIsCollapse() {
        this.isCollapse = !this.isCollapse;
      }
    },
    created() {
      let user = JSON.parse(localStorage.getItem("user"));
      this.username = user.username;
    },
  }
</script>

<style scoped>
  .el-header, .el-footer {
    background-color: #242f42;
    color: #eee;
    text-align: left;
    line-height: 60px;
  }

  .el-aside {
    background-color: #E9EEF3;
    color: #999;
    text-align: center;
    line-height: 200px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #555;
    text-align: center;
    padding-top: 2px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .el-main div {
    background-color: #fff;
    margin: 0 -12px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }

  .el-menu {
    height: 100vh
  }

  element.style .el-menu-item a {
    color: rgb(255, 208, 75) !important;
  }

  /* 自定义样式 */
  .header-title {
    float: left;
    margin-left: 16px;
  }

  .header-user {
    float: right;
    margin-right: 20px;
  }
  
  .header-username {
    margin-left: 8px;
    margin-right: 12px;
    font-weight: bold;
    color: firebrick;
  }

  .header-username::after {
    content: "|";
    margin-left: 16px;
    color: lightgray;
  }
</style>